<?php

namespace App\Exports;

use Dcat\Admin\Grid;
use Dcat\Admin\Grid\Exporters\AbstractExporter as ExportersAbstractExporter;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Dcat\Admin\Grid\Exporters\ExporterInterface;

/**
 * @method $this disableExportAll(bool $value = true)
 * @method $this disableExportCurrentPage(bool $value = true)
 * @method $this disableExportSelectedRow(bool $value = true)
 */
abstract class AbstractExporter extends ExportersAbstractExporter {
    /**
     * 格式化待导出数据.
     *
     * @param  Collection  $data
     * @return array
     */
    public function normalize(Collection $data)
    {
        // $data = $data->toArray();
        foreach ($data as &$row) {
            $row = Arr::dot($row);

            foreach ($row as &$v) {
                if (is_array($v) || is_object($v)) {
                    $v = json_encode($v, JSON_UNESCAPED_UNICODE);
                }
            }
        }

        return $data;
    }
}